import 'package:flutter/material.dart';
import 'package:wan_android_flutter/common/resources/colors/theme_data_extension.dart';

class ColorData implements ThemeExtension<ColorData> {
  final Color textWhite;
  final Color textGray;
  final Color textBlack;
  final Color textBlue;
  final Color bgWhite;
  final Color bgBlue;
  final Color bgDivider;
  final Color bgGray;

  const ColorData(
      {required this.textWhite,
      required this.textGray,
      required this.textBlack,
      required this.textBlue,
      required this.bgWhite,
      required this.bgBlue,
      required this.bgDivider,
      required this.bgGray});

  @override
  ColorData copyWith({
    Color? textWhite,
    Color? textGray,
    Color? textDefault,
    Color? textBlue,
    Color? bgWhite,
    Color? bgBlue,
    Color? bgDivider,
    Color? bgGray,
  }) {
    return ColorData(
      textWhite: textWhite ?? this.textWhite,
      textGray: textGray ?? this.textGray,
      textBlack: textBlack ?? this.textBlack,
      textBlue: textBlue ?? this.textBlue,
      bgWhite: bgWhite ?? this.bgWhite,
      bgBlue: bgBlue ?? this.bgBlue,
      bgDivider: bgDivider ?? this.bgDivider,
      bgGray: bgGray ?? this.bgGray,
    );
  }

  @override
  ColorData lerp(ColorData? other, double t) {
    if (other == null) {
      return this;
    }
    return ColorData._lerp(this, other, t);
  }

  @override
  bool operator ==(Object other) {
    if (other.runtimeType != runtimeType) {
      return false;
    }
    return other is ColorData &&
        other.textWhite == textWhite &&
        other.textGray == textGray &&
        other.textBlack == textBlack &&
        other.textBlue == textBlue &&
        other.bgWhite == bgWhite &&
        other.bgBlue == bgBlue &&
        other.bgDivider == bgDivider &&
        other.bgGray == bgGray;
  }

  @override
  Object get type => ColorData;

  static ColorData of(BuildContext context) => Theme.of(context).colorData;

  static ColorData _lerp(ColorData a, ColorData b, double t) {
    if (identical(a, b)) {
      return a;
    }
    return ColorData(
      textWhite: Color.lerp(a.textWhite, b.textWhite, t)!,
      textGray: Color.lerp(a.textGray, b.textGray, t)!,
      textBlack: Color.lerp(a.textBlack, b.textBlack, t)!,
      textBlue: Color.lerp(a.textBlue, b.textBlue, t)!,
      bgWhite: Color.lerp(a.bgWhite, b.bgWhite, t)!,
      bgBlue: Color.lerp(a.bgBlue, b.bgBlue, t)!,
      bgDivider: Color.lerp(a.bgDivider, b.bgDivider, t)!,
      bgGray: Color.lerp(a.bgGray, b.bgGray, t)!,
    );
  }
}
